package com.zch.user.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zch.domain.Result;
import com.zch.entity.TbDept;
import com.zch.user.service.TbDeptService;
import com.zch.user.mapper.TbDeptMapper;
import com.zch.user.vo.PageVo;
import com.zch.user.vo.TbDeptVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author xuebing
* @description 针对表【tb_dept(科室维护表)】的数据库操作Service实现
* @createDate 2023-10-30 20:28:32
*/
@Service
public class TbDeptServiceImpl extends ServiceImpl<TbDeptMapper, TbDept>
    implements TbDeptService{

    @Autowired
    private TbDeptMapper tbDeptMapper;

    @Override
    public Result TbDeptList(PageVo pageVo, TbDeptVO tbDeptVO) {
        Page<TbDept> page = new Page<>(pageVo.getPageNum(), pageVo.getPageSize());
        Page<TbDept>  tbDeptPage= tbDeptMapper.TbDeptList(page,tbDeptVO);
        return Result.SUCCESS(tbDeptPage);
    }

    @Override
    public Result TbDeptUpdate(TbDeptVO tbDeptVO) {
        TbDept tbDept = new TbDept();
        BeanUtils.copyProperties(tbDeptVO,tbDept);
        boolean b = updateById(tbDept);
        return b?Result.SUCCESS():Result.FAILED(502,"修改失败");
    }

    @Override
    public Result TbDeptDelete(TbDeptVO tbDeptVO) {
        TbDept tbDept = getById(tbDeptVO.getId());
        tbDept.setDeleted(1);

        TbDept tbDeptOne = new TbDept();
        BeanUtils.copyProperties(tbDept,tbDeptOne);

        boolean b = updateById(tbDeptOne);
        return b?Result.SUCCESS():Result.FAILED(502,"删除失败");
    }

    @Override
    public Result TbDeptSave(TbDeptVO tbDeptVO) {

        TbDept tbDept = new TbDept();

        BeanUtils.copyProperties(tbDeptVO,tbDept);
        boolean save = save(tbDept);

        return save?Result.SUCCESS():Result.FAILED(502,"添加失败");
    }
}




